<template>
  <div id="app">
    <sph-header v-show="!$route.meta.hideHeader"></sph-header>
    <router-view></router-view>
    <sph-footer v-show="!$route.meta.hideFooter"></sph-footer>
  </div>
</template>

<script>
import header from "components/header/header.vue";
import footer from "components/footer/footer.vue";
import { mapActions } from "vuex";
export default {
  name: "App",
  components: {
    "sph-header": header,
    "sph-footer": footer,
  },
  methods: {
    ...mapActions([
      "getCategoryList",
      "getBanners",
      "getFloors",
      "getGoodsList",
      "autoLogin",
    ]),
  },
  async created() {
    //每次刷新界面或者重新进入界面都需要自动登录
    if (this.$store.state.user.token) {
      //只有界面刷新时才会做token的检验!!!!
      //如果把这段逻辑移到路由守卫中 不光可以在界面刷新时检验 还可以在路由切换时检验
      await this.autoLogin();
    }
  },
  async mounted() {
    await this.getCategoryList();
    await this.getBanners();
    await this.getFloors();
  },
};
</script>

<style lang='less' scoped>
#app {
  width: 100vw;
}
</style>
